package cn.royan.fl.demos
{
	import cn.royan.fl.ClientSocket;
	import cn.royan.fl.events.NetworkEvent;
	import cn.royan.fl.events.SocketEvent;
	import cn.royan.fl.requests.LoginRequest;
	import cn.royan.fl.utils.Logger;
	import com.flashdynamix.utils.SWFProfiler;
	import flash.display.Sprite;
	/**
	 * ...
	 * @author RoYan
	 */
	public class Main extends Sprite 
	{
		protected var clientSocket:ClientSocket;
		
		public function Main():void
		{
			Logger.debug = true;
			
			SWFProfiler.init( stage, this );
			
			clientSocket = new ClientSocket( "127.0.0.1", 85 );
			clientSocket.addEventListener( SocketEvent.SOCKET_CONNECT, 	socketConnectHandler );
			clientSocket.addEventListener( SocketEvent.SOCKET_CLOSE, 	socketCloseHandler );
			clientSocket.start();
		}
		
		protected function socketConnectHandler(evt:SocketEvent):void
		{
			Logger.tracer( "CONNECT" );
			var loginRequest:LoginRequest = new LoginRequest( "auciferjay", "123123" );
			clientSocket.sendRequest( loginRequest );
		}
		
		protected function socketCloseHandler(evt:SocketEvent):void
		{
			Logger.tracer( "CLOSE" );
			
		}
	}
	
}